<?php

class ProfileController extends BaseController {

    public function showOwnProfile() {
        $with = array(
            'userRelations.userRef',
            'recipes',
            'recipes.user',
            'recipes.likesDislikes',
            'recipes.commentsCount',
            'recipesPending.recipe',
            'recipesPending.recipe.user',
            'recipesPending.recipe.likesDislikes',
            'recipesPending.recipe.commentsCount',            
            'recipesFavourites.recipe',
            'recipesFavourites.recipe.user',
            'recipesFavourites.recipe.likesDislikes',
            'recipesFavourites.recipe.commentsCount',
            'notifications',
            'notifications.userRef'
        );

        $user = User::with($with)->where('user_name', '=', Auth::user()->user_name)->first();
        return View::make('layouts.user-profile', array('user' => $user, 'self' => true));

        //var_dump(DB::getQueryLog());
    }

    public function showUserProfile($user_name) {
        if (Auth::user() && $user_name == Auth::user()->user_name)
            return Redirect::to('profile');

        $with = array(
            'userRelations.userRef',
            'recipes',
            'recipes.user',
            'recipes.likesDislikes',
            'recipes.commentsCount',
            'recipesPending.recipe',
            'recipesPending.recipe.user',
            'recipesPending.recipe.likesDislikes',
            'recipesPending.recipe.commentsCount',            
            'recipesFavourites.recipe',
            'recipesFavourites.recipe.user',
            'recipesFavourites.recipe.likesDislikes',
            'recipesFavourites.recipe.commentsCount',
            'notifications',
            'notifications.userRef'
        );

        $user = User::with($with)->where('user_name', '=', $user_name)->first();
        return View::make('layouts.user-profile', array('user' => $user, 'self' => false));
    }

}
